import request from '@/utils/request'

// 获取字典类型列表
export function getDictCategoryList() {
  return request({
    url: '/admin/dict/category',
    method: 'get'
  })
}

// 添加字典类型
export function addDictCategory(name: string) {
  return request({
    url: '/admin/dict/category',
    method: 'post',
    data: {
      name
    }
  })
}

// 删除字典类型
export function deleteDictCategory(id: number) {
  return request({
    url: `/admin/dict/category/id/${id}`,
    method: 'delete'
  })
}

// 获取字典列表
export function getDictList(dcid: number | string, page?: number) {
  let params = {
    page: page ? page : 1
  }

  return request({
    url: `/admin/dict/category/${dcid}`,
    method: 'get',
    params
  })
}

// 添加字典
export function addDict(dcid: number, value: any, parentId?: number) {
  return request({
    url: '/admin/dict',
    method: 'post',
    data: {
      value,
      category: {
        dcid
      },
      parentId: parentId ? parentId : null
    }
  })
}

// 删除字典
export function deleteDict(id: number) {
  return request({
    url: `/admin/dict/id/${id}`,
    method: 'delete'
  })
}